;; ;; --- open dot config file ---
;; (defvar Hesperus-dot-config-file "~/.spacemacs.d/init.el")
;; (defun Hesperus-open-dot-config-file ()
;;   "Open custom.el in Centaur Emacs path."
;;   (interactive)
;;   (find-file Hesperus-dot-config-file)
;;   (current-buffer))
;; (bind-key* "s-d" #'Hesperus-open-dot-config-file)

;; ;; better func: awesome-pair::jump-out-pair-and-newline
;; ;; --- open newline ---
;; (defun Hesperus-open-newline-inline ()
;;   "Open a newline even if the cursor is Not at end."
;;   (interactive)
;;   (end-of-visual-line)
;;   (newline-and-indent))
;; (dolist (HA-newline-inline-hook
;;          (list
;;           'markdown-mode-hook
;;           'prog-mode-hook))
;;   (add-hook HA-newline-inline-hook
;;             (lambda ()
;;               (local-set-key (kbd "C-o")
;;                              #'Hesperus-open-newline-inline))))

;; --- delete empty lines ---
;; @mayingjun via emacs-cn
(defun Hesperus-delete-empty-line (beg end)
  "Delete empty lines if selected, otherwise the whole buffer."
  (interactive "r")
  (let ((empty-line "^[\t  ]*$"))
    (save-excursion
      (if (region-active-p)
          (flush-lines empty-line beg end)
        (flush-lines empty-line (point-min) (point-max))))))

;; --- keybindings ---

;; switch diff Modes
(bind-key* "C-c m a" 'awesome-pair-mode)
(bind-key* "C-c m e" 'emacs-lisp-mode)
(bind-key* "C-c m l" 'latex-mode)
(bind-key* "C-c m m" 'markdown-mode)
(bind-key* "C-c m o" 'org-mode)
(bind-key* "C-c m p" 'python-mode)
(bind-key* "C-c m P" 'prettify-symbols-mode)
(bind-key* "C-c m r" 'R-mode)
(bind-key* "C-c m s" 'shell-script-mode)
(bind-key* "C-c m t" 'tex-mode)
(bind-key* "C-c m x" 'text-mode)
(bind-key* "C-c m y" 'yaml-mode)

;; same function with Super key
(bind-key* "s-m a" 'awesome-pair-mode)
(bind-key* "s-m e" 'emacs-lisp-mode)
(bind-key* "s-m l" 'latex-mode)
(bind-key* "s-m m" 'markdown-mode)
(bind-key* "s-m o" 'org-mode)
(bind-key* "s-m p" 'python-mode)
(bind-key* "s-m P" 'prettify-symbols-mode)
(bind-key* "s-m r" 'R-mode)
(bind-key* "s-m s" 'shell-script-mode)
(bind-key* "s-m t" 'tex-mode)
(bind-key* "s-m x" 'text-mode)
(bind-key* "s-m y" 'yaml-mode)

;; describe-chAr and codepoint info
(bind-key* "C-c a" 'describe-char)
(bind-key* "s-a" 'describe-char)

;; display Buffer list
(bind-key* "C-c b" 'helm-buffers-list)
(bind-key* "s-b" 'helm-buffers-list)

;; jump with avy-goto-Char
(bind-key* "C-c c" 'avy-goto-char)
(bind-key* "s-c" 'avy-goto-char)

;; Find file in project
(bind-key* "C-c f" 'counsel-projectile-find-file)
(bind-key* "s-f" 'counsel-projectile-find-file)

;; popup maGit status
(bind-key* "C-c g" 'magit-status)
(bind-key* "s-g" 'magit-status)

(bind-key* "C-r" 'query-replace-regexp)

;; use Swiper to Search in minor file
(bind-key* "C-s" 'swiper)

;; use youdao-dicT in Ch layer
(bind-key* "C-c t" #'youdao-dictionary-search-at-point-tooltip)
(bind-key* "s-t" #'youdao-dictionary-search-at-point-tooltip)

;; Quit visualized undo-tree
(bind-key* "C-c q" 'undo-tree-visualizer-quit)
(bind-key* "s-q" 'undo-tree-visualizer-quit)

;; remap M-^ to M-6 (Not type shift)
(bind-key* "M-6" 'delete-indentation)

(bind-key* "M-i" 'symbol-overlay-put)
(bind-key* "M-I" 'symbol-overlay-remove-all)

(provide 'Hesperus-keybindings)
